#!/bin/bash
#功能函数
funcs=`which functions.sh`
if [ "$funcs" != "" ] ;then
    . $funcs
else
    funcs=`dirname $0`/functions.sh
    echo "$PWD"
    echo "funcs=$funcs"
    if [ "$funcs" != "" ] ;then
	. $funcs
    else
	exit
    fi
fi

function mount_smbfs() 
{
echoTextGreen "
remote dir :$1 
mount point:$2
username   :$3
password   :$4
"
remote_dir=$1
mount_point=$2
user=$3
pwd=$4
sudo mkdir -pv $mount_point
smbfs_info=`dpkg -s smbfs|grep "install ok installed"`
if [ "$smbfs_info" = "" ]; then
    sudo apt-get install smbfs
fi
args="-o rw,iocharset=utf8,username=$user,password=$pwd,uid=$USER,gid=$USER"
info=`mount|grep  "$mount_point"`
if [ "$info" = "" ]; then
    echo "mount -t smbfs $args $remote_dir $mount_point"
    sudo mount -t smbfs $args $remote_dir $mount_point
else
    echo $info
fi  
}

function mount_nfsfs()
{
echoTextGreen "
remote dir :$1 
mount point:$2
"
remote_dir=$1
mount_point=$2
sudo mkdir -pv $mount_point
#args="-o rw,iocharset=utf8,username=$user,password=$pwd,uid=$USER,gid=$USER"
args=
info=`mount|grep  "$mount_point"`
if [ "$info" = "" ]; then
    echo "sudo mount -t nfs $args $remote_dir $mount_point $3"
    sudo mount -t nfs $args $remote_dir $mount_point $3
else
    echo $info
fi
}

function mount_ftp()
{
#sudo curlftpfs ftp://downloader:123456@172.20.127.15/images/ /mnt/ftp 
echoTextGreen "
remote dir :$1 
mount point:$2
username   :$3
password   :$4
"
remote_dir=$1
mount_point=$2
user=$3
pwd=$4
sudo mkdir -pv $mount_point
smbfs_info=`dpkg -s curlftpfs|grep "install ok installed"`
if [ "$smbfs_info" = "" ]; then
    sudo apt-get install curlftpfs
fi

uid=`id |grep $USER |awk  '{print $1}' |tr '(|)|=' ' ' |awk '{print $2}'`
args="-o rw,iocharset=utf8,user=$user:$pwd,uid=$uid,gid=$uid,allow_other"
info=`mount|grep  "$mount_point"`
if [ "$info" = "" ]; then
    echo "sudo curlftpfs  $args ftp:$remote_dir $mount_point"
    sudo curlftpfs  $args ftp:$remote_dir $mount_point
else
    echo $info
fi  
}

function mount_ftp_15()
{
	mount_ftp //smartftp/images/ /mnt/ftp15 uploader up@loader
}

function mount_ftp_update()
{
mount_ftp //111.1.45.243/updatefiles/ /mnt/ftpupdate upgrade "up\$#@!grade@5"
}

function smartphone_smb.sh()
{
mount_smbfs    //172.20.120.214/upgrade/  /mnt/smb/smartphone/upgrade  upgrade upgrade
mount_smbfs    //172.20.120.214/public/  /mnt/smb/smartphone/public  public 123456
}

function mount172.20.126.223_软件.sh()
{
#存放mtk文档
mount_smbfs    //172.20.126.223/软件/  /mnt/smb/172.20.126.223/软件  iQoo-SW  iqoosw
}

function mount172.20.126.223_公共.sh()
{
#存放mtk文档
mount_smbfs    //172.20.126.223/公共/  /mnt/smb/172.20.126.223/公共  iQoo-SW  iqoosw
}

function mount_all.sh()
{
mount_ftp_15
smartphone_smb.sh
mount172.20.126.223_软件.sh
mount172.20.126.223_公共.sh
}

function unmount_all.sh()
{
points=`mount |grep 172 |awk '{print $1}' |tr '\n' ' '`
points1=`mount |grep curlftpfs |awk '{print $1}' |tr '\n' ' '`
points="$points $points1"
for point in $points
do
echo "sudo umount  $point"
sudo umount  $point
done
}


#脚步入口：解析参数
while test $# != 0
do
    case $1 in
	-r)
	    shift
	    version=$1
	    ;;
	-m)
	    shift
	    mode=$1
	    ;;
        *)
	    mode=$1
	    ;;
       esac
       shift
done

if [ "$mode" == "auto" ]; then
    echo "auto"
    setup-moban.sh
else
    menu_list="
mount_ftp_15
mount_ftp_update
smartphone_smb.sh
mount172.20.126.223_软件.sh
mount172.20.126.223_公共.sh
mount_all.sh
unmount_all.sh
"
    echoTextBlue "Please select"
    result=`sh_menu_select "$menu_list"`
    echo "${result}"
    ${result}
fi

